package com.lzw.breezeNovel.WebAdmin.controller;


import com.lzw.breezeNovel.WebAdmin.service.AdminLoginService;
import com.lzw.breezeNovel.WebAdmin.vo.AdminLoginVo;
import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.pojo.user.AdminLogin;
import com.lzw.breezeNovel.model.entity.query.PaginationResultQuery;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@SuppressWarnings("all")
public class AdminLoginController {

    /**
     * 注入service接口
     */
    @Resource
    private AdminLoginService adminLoginService;

    /**
     * 注册接口
     */
    @RequestMapping("/login/register")
    public Result register(@RequestBody AdminLogin adminLogin){
        adminLoginService.register(adminLogin);
        return Result.ok();
    }

    /**
     * 登入接口
     */
    @RequestMapping("/login")
    public Result login(@RequestBody AdminLogin adminLogin){
        String token = adminLoginService.login(adminLogin);
        return Result.ok(token);
    }

    /**
     * 新增用户
     */
    @PostMapping("/addLoginUser")
    public Result addAdmin(@RequestBody AdminLogin adminLogin){
        adminLoginService.addLoginUser(adminLogin);
        return Result.ok();
    }

    /**
     * 查询用户
     */
    @PostMapping("/getAllLoginUser")
    public Result<PaginationResultQuery<AdminLoginVo>> queryLoginUser(@RequestBody AdminLogin adminLogin){
        PaginationResultQuery<AdminLoginVo> paginationResultVo = adminLoginService.queryLoginUser(adminLogin);
        return Result.ok(paginationResultVo);
    }

    /**
     * 批量删除用户信息
     */
    @DeleteMapping("/deleteLoginUsers/{ids}")
    public Result deleteLoginUserBatch(@PathVariable("ids") Integer[] ids){
        adminLoginService.deleteLoginUserBatch(ids);
        return Result.ok();
    }

    /**
     * 修改用户信息
     */
    @PostMapping("/updateLoginUser")
    public Result updateLoginUser(@RequestBody AdminLogin adminLogin){
        adminLoginService.updateLoginUser(adminLogin);
        return Result.ok();
    }

    /**
     * 获取当前用户信息
     */
    @GetMapping("/getCurrentLoginUser")
    public Result<AdminLoginVo> getLoginUser(){
        AdminLoginVo adminLogin = adminLoginService.getLoginUser();
        return Result.ok(adminLogin);
    }

    /**
     * 修改当前用户信息
     */
    @PostMapping("/updateCurrentLoginUser")
    public Result updateCurrentLoginUser(@RequestBody AdminLogin adminLogin){
        adminLoginService.updateCurrentLoginUser(adminLogin);
        return Result.ok();
    }

}
